package com.wang.openApigateway.inservice;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class LogService {

    /**
     * 打印请求头中的参数
     */
    public void printHeaderParamLog(HttpHeaders headers) {
        log.info("accessKey: " + headers.getFirst("accessKey"));
        log.info("nonce " + headers.getFirst("nonce"));
        log.info("timestamp " + headers.getFirst("timestamp"));
        log.info("body " + headers.getFirst("body")); //body {"username":"123"}
        log.info("sign " + headers.getFirst("sign"));
    }

    /**
     * 打印地址信息
     *
     * @param request
     */
    public void printExchangeParamLog(ServerHttpRequest request) {
        log.info("请求唯一标识:" + request.getId());
        log.info("请求路径:" + request.getPath().value());
        String method = String.valueOf(request.getMethod());
        log.info("请求方法:" + method);
        log.info("请求参数:" + request.getQueryParams());
        String remoteAddress = String.valueOf(request.getRemoteAddress());
        log.info("请求来源地址:" + remoteAddress);
        String sourceAddress = request.getURI().getHost();
        log.info("请求主机地址: {}", sourceAddress);
    }
}
